From: debris Date: Thu, 8 Feb 2018 21:50:35 +0000 (+0100) Subject: Add helpful message when running cargo doc --open in the root of the workspace, fixes... X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~3^2~7^2 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=bd7ba3c89c4ede4e1b3db930aefe4dff59ba1184;p=cargo.git Add helpful message when running cargo doc --open in the root of the workspace, fixes #4962 --- diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index 9527f64ae..3a722de2f 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -59,7 +59,10 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> { if options.open_result { let name = if pkgs.len() > 1 { - bail!("Passing multiple packages and `open` is not supported") + bail!("Passing multiple packages and `open` is not supported.\n\ + Please re-run this command with `-p ` where `` \ + is one of the following:\n {}", + pkgs.iter().map(|p| p.name()).collect::>().join("\n ")); } else if pkgs.len() == 1 { pkgs[0].name().replace("-", "_") } else { diff --git a/tests/doc.rs b/tests/doc.rs index 25ac13048..1464bdc62 100644 --- a/tests/doc.rs +++ b/tests/doc.rs @@ -1034,3 +1034,37 @@ fn doc_all_member_dependency_same_name() { .with_stderr_contains("[..] Updating registry `[..]`") .with_stderr_contains("[..] Documenting a v0.1.0 ([..])")); } + +#[test] +fn doc_workspace_open_help_message() { + let p = project("foo") + .file("Cargo.toml", r#" + [workspace] + members = ["foo", "bar"] + "#) + .file("foo/Cargo.toml", r#" + [package] + name = "foo" + version = "0.1.0" + "#) + .file("foo/src/lib.rs", "") + .file("bar/Cargo.toml", r#" + [package] + name = "bar" + version = "0.1.0" + "#) + .file("bar/src/lib.rs", "") + .build(); + + // The order in which bar is compiled or documented is not deterministic + assert_that(p.cargo("doc") + .arg("--all") + .arg("--open"), + execs().with_status(101) + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") + .with_stderr_contains("error: Passing multiple packages and `open` is not supported.") + .with_stderr_contains("Please re-run this command with `-p ` where `` is one of the following:") + .with_stderr_contains(" foo") + .with_stderr_contains(" bar")); +}